package cn.yuhh.api.validator;


import cn.yuhh.api.annotation.NotNull;
import cn.yuhh.api.exception.ValidatorException;

import java.lang.annotation.Annotation;
import java.util.Map;

/**
 * 非空验证
 */
public class NotNullValidator implements AnnotationValidator{

    @Override
    public void handler(Annotation annotation, Map request) {
        NotNull notNull = (NotNull) annotation;
        String[] names = notNull.name();

        for(String n : names){
            Object obj = request.get(n);
            if(obj == null || "".equals(obj)){
                throw new ValidatorException(n + " must not null");
            }
        }
    }
}
